package com.lsh.payment.core.strategy.bill;

import com.lsh.payment.core.model.payenum.DownloadBill;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 16/11/24
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
public class BillStrategyContext {

    private Logger logger = LoggerFactory.getLogger(BillStrategyContext.class);

    private BillStrategy billStrategy;

    /**
     * @param payType 类型
     * @return boolean
     */
    public boolean downloadBill(String payType) {

        DownloadBill downloadBill = DownloadBill.getDownloadBill(payType);
        if (null == downloadBill) {
            logger.info("payType {} 目前不支持该类型的对账单下载", payType);
            return false;
        }

        String payChannelName = downloadBill.getPayChannelName();

        int billType = downloadBill.getBillType();

        if (StringUtils.isNotBlank(payChannelName)) {

            billStrategy = BillStrategyFactory.getInstance().creator(payChannelName);
            return billStrategy.downloadBillByDate(null, billType);
        }

        return false;
    }

}
